home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 12 / Game / Game.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  4.3 KB  |  112 lines

  1. //-----------------------------------------------------------------------------
  2. // The derived game state where all the game's processing happens.
  3. //
  4. // Programming a Multiplayer First Person Shooter in DirectX
  5. // Copyright (c) 2004 Vaughan Young
  6. //-----------------------------------------------------------------------------
  7. #ifndef GAME_H
  8. #define GAME_H
  9.  
  10. //-----------------------------------------------------------------------------
  11. // State ID Define
  12. //-----------------------------------------------------------------------------
  13. #define STATE_GAME 1
  14.  
  15. //-----------------------------------------------------------------------------
  16. // Custom Network Message Defines
  17. //-----------------------------------------------------------------------------
  18. #define MSGID_PLAYER_HEALTH          0x12005
  19. #define MSGID_PLAYER_MOVE_UPDATE     0x12006
  20. #define MSGID_PLAYER_LOOK_UPDATE     0x12007
  21. #define MSGID_PLAYER_SCORE           0x12008
  22. #define MSGID_SPAWN_POINT_REQUEST    0x12011
  23. #define MSGID_SPAWN_POINT            0x12012
  24. #define MSGID_SPAWN_PLAYER           0x12013
  25.  
  26. //-----------------------------------------------------------------------------
  27. // Player Health Message Structure
  28. //-----------------------------------------------------------------------------
  29. struct PlayerHealthMsg : public NetworkMessage
  30. {
  31.     float health; // Absolute health of the player.
  32. };
  33.  
  34. //-----------------------------------------------------------------------------
  35. // Player Move Message Structure
  36. //-----------------------------------------------------------------------------
  37. struct PlayerMoveUpdateMsg : public NetworkMessage
  38. {
  39.     D3DXVECTOR3 translation; // Player's translation.
  40.     float drive; // Player's drive direction.
  41.     float strafe; // Player's strafe direction.
  42.     bool fire; // Indicate's if the player is firing their weapon.
  43. };
  44.  
  45. //-----------------------------------------------------------------------------
  46. // Player Look Update Message Structure
  47. //-----------------------------------------------------------------------------
  48. struct PlayerLookUpdateMsg : public NetworkMessage
  49. {
  50.     float viewTilt; // Player's view tilt (i.e. rotation around the x axis).
  51.     float rotationY; // Player's rotation around the y axis.
  52. };
  53.  
  54. //-----------------------------------------------------------------------------
  55. // Player Score Message Structure
  56. //-----------------------------------------------------------------------------
  57. struct PlayerScoreMsg : public NetworkMessage
  58. {
  59.     unsigned long frags; // Player's frag count.
  60.     unsigned long deaths; // Player's death tally.
  61. };
  62.  
  63. //-----------------------------------------------------------------------------
  64. // Spawn Point Message Structure
  65. //-----------------------------------------------------------------------------
  66. struct SpawnPointMsg : public NetworkMessage
  67. {
  68.     long spawnPoint; // ID of the spawn point to use.
  69. };
  70.  
  71. //-----------------------------------------------------------------------------
  72. // Spawn Point Message Structure
  73. //-----------------------------------------------------------------------------
  74. struct SpawnPlayerMsg : public NetworkMessage
  75. {
  76.     D3DXVECTOR3 translation; // Translation to spawn the player at.
  77. };
  78.  
  79. //-----------------------------------------------------------------------------
  80. // Game Class
  81. //-----------------------------------------------------------------------------
  82. class Game : public State
  83. {
  84. public:
  85.     Game();
  86.  
  87.     virtual void Load();
  88.     virtual void Close();
  89.  
  90.     virtual void RequestViewer( ViewerSetup *viewer );
  91.     virtual void Update( float elapsed );
  92.     virtual void Render();
  93.  
  94.     void HandleNetworkMessage( ReceivedMessage *msg );
  95.  
  96. private:
  97.     Material *m_crosshair; // Material used to render the crosshair.
  98.  
  99.     char m_scoreBoardNames[MAX_PATH]; // Text for displaying the names of all the connected players.
  100.     char m_scoreBoardFrags[MAX_PATH]; // Text for displaying each player's frag count.
  101.     char m_scoreBoardDeaths[MAX_PATH]; // Text for displaying each player's death tally.
  102.     Font *m_scoreBoardFont; // Font used to render the score board.
  103.  
  104.     PlayerManager *m_playerManager; // Player manager.
  105. };
  106.  
  107. //-----------------------------------------------------------------------------
  108. // Externals
  109. //-----------------------------------------------------------------------------
  110. extern Game *g_game;
  111.  
  112. #endif